from typing import List

def longest_common_prefix(strs: List[str]) -> str:
    if not strs:                 # 空数组
        return ""
    
    # 以第一个字符串为基准
    prefix = strs[0]
    
    for s in strs[1:]:
        # 不断缩短 prefix，直到它变成与 s 的公共前缀
        while not s.startswith(prefix):
            prefix = prefix[:-1]
            if not prefix:
                return ""
    
    return prefix


# 简单测试
if __name__ == "__main__":
    test_cases = [
        ["flower", "flow", "flight"],
        ["dog", "racecar", "car"],
        ["interspecies", "interstellar", "interstate"],
        ["", "b"],
        ["single"],
        []
    ]
    for case in test_cases:
        print(f"{case} -> {longest_common_prefix(case)}")